<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\News;
use App\Models\Shop;
use Illuminate\Http\Request;
use App\Models\Authorization;
use Illuminate\Support\Facades\DB;
use Log;

class IndexController extends BaseController
{
    /**
     *  获取每日新闻与推荐商家
     * 
     */
    public function recommends(Request $request){
		//取最新一篇文章
    	$oneNews = News::orderBy('id', 'desc')->first();
		$retNews = [];
		$retShop = [];
		if($oneNews){
			$retNews = [
				'id' => $oneNews['id'],
				'created_at' => $oneNews['created_at'],
				'introduce' => str_limit($oneNews['introduce'], '50', '...'),
			];
		}
		$shopIds = [1,2,3];
		//取三个商家
		$shops = Shop::whereIn('id', $shopIds)->get();
		if($shops){
			foreach($shops as $shop){
				$logo = $shop['logo'] ? env('CUT_IMAGE_UTL') . $shop['logo'] : "";
				$retShop[] = [
					'id' => $shop['id'],
					'created_at' => $shop['created_at'],
					'introduce' => $shop['introduce'],
					'name' => $shop['name'],
					'logo' => $logo,
					'latitude' => $shop['latitude'],
					'longitude' => $shop['longitude'],
				];
			}
		}
		$ret = [
			'news' => $retNews,
			'shop' => $retShop,
		];
		return $this->returnSuccess($ret);
    }
}
